# encoding: utf-8
# pylint: disable=too-few-public-methods,invalid-name,missing-docstring
import os


class BaseConfig(object):
    SECRET_KEY = 'winit-ucloud-agent-secret_key'

    PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))

    # SQLALCHEMY_DATABASE_URI = 'sqlite:///%s' % (os.path.join(PROJECT_ROOT, "example.db"))
    # SQLALCHEMY_DATABASE_URI = "mysql://%s:%s@%s:%d/%s?charset=utf8&use_unicode=0" % (
    #     'root', 'winit2015',
    #     '127.0.0.1', 3306,
    #     'ucloud_agent'
    # )
    SQLALCHEMY_DATABASE_URI = "mysql+pymysql://%s:%s@%s:%d/%s?charset=utf8&use_unicode=0" % (
        'root', 'winit2015',
        '127.0.0.1', 3306,
        'ucloud_agent'
    )
    # 自动回收连接的秒数。这对 MySQL 是必须的，默认 情况下 MySQL 会自动移除闲置 8 小时或者以上的连接。 需要注意地是如果使用 MySQL 的话， Flask-SQLAlchemy 会自动地设置这个值为 2 小时。
    SQLALCHEMY_POOL_RECYCLE = 1200
    # 控制在连接池达到最大值后可以创建的连接数。当这些额外的 连接回收到连接池后将会被断开和抛弃。
    SQLALCHEMY_MAX_OVERFLOW = 10

    DEBUG = False

    AUTHORIZATIONS = {
        'oauth2_password': {
            'type': 'oauth2',
            'flow': 'password',
            'scopes': {},
            'tokenUrl': '/auth/oauth2/token',
        },
        # TODO: implement other grant types for third-party apps
        # 'oauth2_implicit': {
        #    'type': 'oauth2',
        #    'flow': 'implicit',
        #    'scopes': {},
        #    'authorizationUrl': '/auth/oauth2/authorize',
        # },
    }

    ENABLED_MODULES = (
        'schedule',
        'database',
        'pipelines',
        'apps',
        'redises',
        'vcloud',
        'zones',
        # 'autotest',
        'notify',
        # 'thread',
        'common',
        'api',
    )

    STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')

    SWAGGER_UI_JSONEDITOR = True
    SWAGGER_UI_OAUTH_CLIENT_ID = 'documentation'
    SWAGGER_UI_OAUTH_REALM = 'Authentication for ucloud-agent documentation'
    SWAGGER_UI_OAUTH_APP_NAME = 'ucloud-agent documentation'

    # TODO: consider if these are relevant for this project
    SQLALCHEMY_TRACK_MODIFICATIONS = True
    CSRF_ENABLED = True
    UCLOUD_MASTER_URL = 'http://172.16.3.166:5002/api/v1'


class ProductionConfig(BaseConfig):
    pass


class DevelopmentConfig(BaseConfig):
    DEBUG = True


class TestingConfig(BaseConfig):
    TESTING = True

    # Use in-memory SQLite database for testing
    SQLALCHEMY_DATABASE_URI = 'sqlite://'


class BeetleConfig(object):
    APP_PATCH_PATH = '/mnt/build/beetle/patching'

    PACKAGE_LATEST_NAS_PATH = '/mnt/winitRelease/latest.product'

    CONTAINER_APP_RUNNTIME_LOG_HOME = '/usr/local/logs/ucloud-agent/app-runtime'

    CONTAINER_TEMPLATE_PATH = '/mnt/build/ucloud/container_template'

    DUMP_DEMO_BASE_PATH = '/mnt/onlinedb/latest.product.mini'

    DUMP_PRODUCT_BASE_PATH = '/mnt/onlinedb/latest.product'

    DB_SCRIPT_PATH = os.getcwd() + '/app/modules/database/backup'

    TEMP_PATH = '/usr/local/temp'

    APP_DEPLOY_BASE_PATH = '/usr/local/app'

    CASSANDRA_HOME_PATH = '/usr/local/db/cassandra'

    PIPELINE_DB_LOG_PATH = '/usr/local/logs/ucloud-agent/pip'

    PIPELINE_APP_LOG_PATH = '/usr/local/logs/ucloud-agent/app-pipt'

    INIT_APP_LOG_PATH = '/usr/local/logs/ucloud-agent/app-init'

    APP_LOG_PATH = '/usr/local/logs/ucloud-agent/app-runtime'

    BEETLE_API_URL = 'http://172.16.3.166:8081/beetle'
    BEETLE_PLAN_URL = 'http://172.16.3.166:5003/api/v1'

    UCLOUD_AGENT_API = 'http://127.0.0.1:5000/api/v1'
    UCLOUD_AGENT_HOST = '127.0.0.1'
    UCLOUD_AGENT_PORT = 5000
    UCLOUD_AGENT_API_CONTEXT = '/api/v1'

    AD_DB_DNS = '127.0.0.1'

    AD_DB_PORT = '1521'

    # app must startup in 5 minute
    UCLOUD_APP_STARTUP_TIMEOUT = 100

    UCLOUD_APP_LOG_LEVEL = "INFO"

    UCLOUD_APP_STARTUP_SUCCESS_EXPRESSIONS = [
        r"INFO: Server startup in \d* ms"]

    UCLOUD_APP_STARTUP_FAILED_EXPRESSIONS = [r".*Exception:.*"]

    ILS_PROJECT = []
